/* 
    arduino
    
    Protospec Home Controller
    
    Copyright (C) 2008  Steven Hepting

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

#include <Wire.h>

uint8_t outbuf[6]; // nunchuck output is 6 bytes of I2C data
uint8_t cnt = 0;
uint8_t ledPin = 13;
uint8_t led_no = 5;
uint8_t state = 0;

// Temperature
uint8_t temperature;
uint8_t temp_pin = 3;
int temp_var;

// Loop variables
unsigned long curr_time;
unsigned long next_time = 0;
#define TEMP_WAIT 10000
#define WAIT 50

void setup () {
  beginSerial (115200);
}

void loop () {
  curr_time = millis();
    
    if (curr_time > next_time){
      Serial.print(curr_time, DEC);
      Serial.print(" ");
      Serial.print(next_time, DEC);
      Serial.print(" ");
      get_temp();
      Serial.print("\r\n");
      next_time = curr_time + TEMP_WAIT;
    }
    
  delay(WAIT);
}


void get_temp()
{
  temp_var = analogRead(temp_pin);
  temperature = map(temp_var, 0, 1023, 0, 500);
  Serial.print("t");
  Serial.print(temperature, DEC);
  Serial.print(" ");
}
